//
//  LogoDA.m
//  weiGuan
//
//  Created by Zhou Ya on 2/18/14.
//
//

#import "LogoDA.h"

@interface LogoDA () {
    TBL_USER_SESSION_INFO *sessionInfo;
}
@end

@implementation LogoDA

- (void)insertSessionInfo:(NSString *)sessionId userId:(NSString *)userId{
    //create object
    sessionInfo = [TBL_USER_SESSION_INFO MR_createInContext:[NSManagedObjectContext MR_defaultContext]];
    
    sessionInfo.jsessionId = sessionId;
    sessionInfo.userId = userId;
    sessionInfo.createdTime = [NSDate date];
    sessionInfo.updatedTime = [NSDate date];
    sessionInfo.lastRefreshTime = [NSDate date];
    
    [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
}

- (TBL_USER_SESSION_INFO *)getSessionInfo:(NSString *)sessionId{
    NSArray *dataResult = [TBL_USER_SESSION_INFO MR_findByAttribute:@"jsessionId" withValue:sessionId inContext:[NSManagedObjectContext MR_defaultContext]];
    
    if (dataResult == nil || [dataResult count] == 0) {
        return nil;
    }
    else {
        return dataResult[0];
    }
}

@end
